<?php

/**
 * @Author: chenjianghui
 * @Date:   2018-08-08 11:56:15
 * @Last Modified by:   chenjianghui
 * @Last Modified time: 2018-08-09 19:11:50
 */
namespace app\common\model;

use think\Model;

class BasicConfig extends Model
{
    protected $name = 'config';

    /*
     * 通过type获取配置信息
     *
     * @params $config_type
     * */
    public static function getConfigByType($config_type)
    {
        $where['type'] = $config_type;
        $config_list   = self::where($where)->field(['key', 'value'])->select();
        $result        = json_decode(json_encode($config_list), true);
        $result        = array_column($result, 'value', 'key');
        $rel_result    = [];
        foreach ($result as $key => $vo) {
            $rel_result[$config_type . '_' . $key] = $result[$key];
        }

        return $rel_result;
    }

    /**
     * 服务器版本信息获取
     * @Author   chenjianghui
     * @DateTime 2018-07-04T11:48:35+0800
     * @return   [type]                   [description]
     */
    public static function getVersionConfig($device)
    {
        $result  = [];
        switch ($device) {
        	case 'ios':
        		$version = [ 'version_version_ios_url', 'version_version_ios'];
        		break;
        	case 'android':
        		$version = ['version_version', 'version_version_android', 'version_version_android_explain', 'version_version_android_url'];
        		break;
        	default:
        		# code...
        		break;
        }

        $client  = self::getConfigByType('version');
        foreach ($client as $key => $vo) {
            if (in_array($key, $version)) {
                $result[$key] = $vo;
            }
        }
        switch ($device) {
        	case 'android':
        		$result['version_version_android'] = (int) $result['version_version_android'];
        		break;
        	default:
        		break;
        }
        return $result;
    }
}
